from flask import Flask,render_template,request,escape

app=Flask(__name__)

def log_request(req:"Flask_requset",res:str):
	with open("jilu.log.","a") as log:
		print(req.form,req.remote_addr,req.user_agent,res,file=log,sep="|")


@app.route("/")
def Hello():
	return "Hello"

@app.route("/shuru")
def hello_shuru():
	return render_template("shuru.html",the_title="hello_entry web")

@app.route("/jisuan",methods=["POST"])
def hello_jisuan():
	phrase = request.form["phrase"]
	letters = request.form["letters"]
	results = float(phrase) + float(letters)
	return render_template('jisuan.html',the_jisuan=results)

@app.route("/jilu")
def hello_jilu():
	with open("jilu.log","r") as log:
		contents = []
		for item in log:
			contents.append([])
			for i in item.split("|"):
				contents[-1].append(escape(i))


	log_title = ["第一位数","第二位数","计算结果"]
	return render_template("jilu.html",the_data=contents,the_log_title=log_title)

if __name__ == '__main__':
	app.run(debug=True)
